package co.baiku.boot.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConditionalOnProperty("ajavaer.weixin.mini-program.appid")
@ConfigurationProperties(prefix = "ajavaer.weixin.mini-program")
public class WeixinMiniProgramConfig {

    private String appid;
    private String secret;

    private String accessTokenCacheKey = "WEIXIN_MINI_ACCESSTOKEN_CACHE";
    private String sessionCacheKey = "WEIXIN_MINI_SESSION_CACHE";

    private String code2session_url = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
    private String get_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s";
    private String send_template_url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=%s";
    private String uniform_send_url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token=%s";
    private String subscribe_message_url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=%s";

    public String getUniform_send_url(String accessToken) {
        return String.format(uniform_send_url, accessToken);
    }

    public void setUniform_send_url(String uniform_send_url) {
        this.uniform_send_url = uniform_send_url;
    }

    public String getCode2session_url(String code) {
        return String.format(code2session_url, this.appid, this.secret, code);
    }

    public void setSubscribe_message_url(String subscribe_message_url) {
        this.subscribe_message_url = subscribe_message_url;
    }

    public String getSubscribe_message_url(String accessToken) {
        return String.format(subscribe_message_url, accessToken);
    }

    public String getGet_token_url() {
        return String.format(get_token_url, this.appid, this.secret);
    }

    public String getSend_template_url(String access_token) {
        return String.format(send_template_url, access_token);
    }

    public String getAccessTokenCacheKey() {
        return accessTokenCacheKey;
    }

    public void setAccessTokenCacheKey(String accessTokenCacheKey) {
        this.accessTokenCacheKey = accessTokenCacheKey;
    }

    public String getSessionCacheKey(String openId) {
        return sessionCacheKey + "_" + openId;
    }

    public void setSessionCacheKey(String sessionCacheKey) {
        this.sessionCacheKey = sessionCacheKey;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getSecret() {
        return secret;
    }

    public void setSecret(String secret) {
        this.secret = secret;
    }

    public String getSessionCacheKey() {
        return sessionCacheKey;
    }

    public String getCode2session_url() {
        return code2session_url;
    }

    public void setCode2session_url(String code2session_url) {
        this.code2session_url = code2session_url;
    }

    public void setGet_token_url(String get_token_url) {
        this.get_token_url = get_token_url;
    }

    public String getSend_template_url() {
        return send_template_url;
    }

    public void setSend_template_url(String send_template_url) {
        this.send_template_url = send_template_url;
    }
}
